home *** CD-ROM | disk | FTP | other *** search
/ Greenhouse Effect Detection Expriment / NASA Greenhouse Effect Detection Expriment 1992 - Disc 2.iso / software / dos / cdf22pc / src / lib / cdf_c_if.c next >
Encoding:
C/C++ Source or Header  |  1992-02-28  |  16.2 KB  |  516 lines

  1. /******************************************************************************
  2. *
  3. *  NSSDC/CDF                        CDF C interface.
  4. *
  5. *  Version 2.0, 10-Feb-92, ST Systems (STX)
  6. *
  7. *  Modification history:
  8. *
  9. *   V1.0   1-Jun-91, J Love    Original version (for CDF V2.1).  This is a
  10. *                combination of cdf.c, cdfattr.c and cdfvar.c.
  11. *                Most of these functions can be replaced by
  12. *                the macros in 'cdf.h'.
  13. *   V1.1  30-Jul-91, J Love    Use 'CDFlib'.
  14. *   V2.0  10-Feb-92, J Love    IBM PC port.
  15. *
  16. ******************************************************************************/
  17.  
  18. #include "cdflib.h"
  19.  
  20. /******************************************************************************
  21. * CDFcreate.
  22. ******************************************************************************/
  23.  
  24. #if !C_INTERFACE_MACROS
  25. CDFstatus CDFcreate(CDFname,numDims,dimSizes,encoding,majority,id)
  26. char    *CDFname;    /* in -- CDF path name (external name) */
  27. long    numDims;    /* in -- number of dims, 0..CDF_MAX_DIMS */
  28. long    dimSizes[];    /* in -- size for each declared dimension */
  29. long    encoding;    /* in -- {HOST_ENCODING, NETWORK_ENCODING} */
  30. long    majority;      /* in -- {ROW_MAJOR, COL_MAJOR vectors} */
  31. CDFid    *id;        /* out-- CDF id */
  32. {
  33. return CDFlib (CREATE_, CDF_, CDFname, numDims, dimSizes, id,
  34.            PUT_, CDF_ENCODING_, encoding,
  35.              CDF_MAJORITY_, majority,
  36.            NULL_);
  37. }
  38. #endif
  39.  
  40. /******************************************************************************
  41. * CDFopen.
  42. ******************************************************************************/
  43.  
  44. #if !C_INTERFACE_MACROS
  45. CDFstatus CDFopen(CDFname,id)
  46. char    *CDFname;    /* in -- CDF path name (external name) */
  47. CDFid    *id;        /* out-- CDF id */
  48. {
  49. return CDFlib (OPEN_, CDF_, CDFname, id,
  50.            NULL_);
  51. }
  52. #endif
  53.  
  54. /******************************************************************************
  55. * CDFdoc.
  56. ******************************************************************************/
  57.  
  58. #if !C_INTERFACE_MACROS
  59. CDFstatus CDFdoc(id,version,release,text)
  60. CDFid    id;        /* in -- CDF id */
  61. long    *version;     /* out-- software version number */
  62. long    *release;     /* out-- software release number */
  63. char    *text;          /* out-- pointer to text data    */
  64. {
  65. return CDFlib (SELECT_, CDF_, id,
  66.            GET_, CDF_VERSION_, version,
  67.              CDF_RELEASE_, release,
  68.              CDF_COPYRIGHT_, text,
  69.            NULL_);
  70. }
  71. #endif
  72.  
  73. /******************************************************************************
  74. * CDFinquire.
  75. ******************************************************************************/
  76.  
  77. #if !C_INTERFACE_MACROS
  78. CDFstatus CDFinquire(id,numDims,dimSizes,encoding,majority,maxRec,numVars,
  79.              numAttrs)
  80. CDFid    id;        /* in -- CDF id */
  81. long    *numDims;    /* out-- number of dims, 0..CDF_MAX_DIMS */
  82. long    dimSizes[];    /* out-- size of each dimension */
  83. long    *encoding;     /* out-- { HOST_ENCODING, NETWORK_ENCODING } */
  84. long    *majority;    /* out-- { ROW_MAJOR or COL_MAJOR }     */
  85. long    *maxRec;    /* out-- Max record number for all variables */
  86. long    *numVars;    /* out-- number of variables */
  87. long    *numAttrs;    /* out-- number of attributes */
  88. {
  89. return CDFlib (SELECT_, CDF_, id,
  90.            GET_, CDF_NUMDIMS_, numDims,
  91.              CDF_DIMSIZES_, dimSizes,
  92.              CDF_ENCODING_, encoding,
  93.              CDF_MAJORITY_, majority,
  94.              CDF_MAXREC_, maxRec,
  95.              CDF_NUMVARS_, numVars,
  96.              CDF_NUMATTRS_, numAttrs,
  97.            NULL_);
  98. }
  99. #endif
  100.  
  101. /******************************************************************************
  102. * CDFclose.
  103. ******************************************************************************/
  104.  
  105. #if !C_INTERFACE_MACROS
  106. CDFstatus CDFclose(id)
  107. CDFid id;        /* in -- CDF id */
  108. {
  109. return CDFlib (SELECT_, CDF_, id,
  110.            CLOSE_, CDF_, 
  111.            NULL_);
  112. }
  113. #endif
  114.  
  115. /******************************************************************************
  116. * CDFdelete.
  117. ******************************************************************************/
  118.  
  119. #if !C_INTERFACE_MACROS
  120. CDFstatus CDFdelete(id)
  121. CDFid id;        /* in -- CDF id */
  122. {
  123. return CDFlib (SELECT_, CDF_, id,
  124.            DELETE_, CDF_,
  125.            NULL_);
  126. }
  127. #endif
  128.  
  129. /******************************************************************************
  130. * CDFerror.
  131. ******************************************************************************/
  132.  
  133. #if !C_INTERFACE_MACROS
  134. CDFstatus CDFerror (stat, text)
  135. CDFstatus stat;    /* in -- a CDF status value returned from 
  136.                any CDF* function that returns a 
  137.                CDFstatus type.  */
  138. char *text;
  139. {
  140. return CDFlib (SELECT_, CDF_STATUS_, stat,
  141.            GET_, STATUS_TEXT_, text,
  142.            NULL_);
  143. }
  144. #endif
  145.  
  146. /******************************************************************************
  147. * CDFattrCreate.
  148. ******************************************************************************/
  149.  
  150. #if !C_INTERFACE_MACROS
  151. CDFstatus CDFattrCreate(id,attrName,attrScope,attrNum)
  152. CDFid    id;        /* in -- CDF id */
  153. char    *attrName;    /* in -- attribute name */
  154. long    attrScope;    /* in -- scope of attribute, either VARIABLE or
  155.                GLOBAL - these names may be changed */
  156. long    *attrNum;    /* out -- attribute number */
  157. {
  158. return CDFlib (SELECT_, CDF_, id,
  159.            CREATE_, ATTR_, attrName, attrScope, attrNum,
  160.            NULL_);
  161. }
  162. #endif
  163.  
  164. /******************************************************************************
  165. * CDFattrCorrectScope.
  166. ******************************************************************************/
  167.  
  168. #if !C_INTERFACE_MACROS
  169. CDFstatus CDFattrCorrectScope(id,attrNum,attrScope)
  170. CDFid id;
  171. long attrNum;
  172. long attrScope;
  173. {
  174. return CDFlib (SELECT_, CDF_, id,
  175.             ATTR_, attrNum,
  176.            PUT_, ATTR_SCOPE_, attrScope,
  177.            NULL_);
  178. }
  179. #endif
  180.  
  181. /******************************************************************************
  182. * CDFattrNum.  Can't implement with macro since it is the attribute number
  183. * which is to be returned (unless an error).
  184. ******************************************************************************/
  185.  
  186. long CDFattrNum(id,attrName)
  187. CDFid    id;        /* in -- CDF id */
  188. char    *attrName;    /* in -- attribute name */
  189. {
  190. CDFstatus status;
  191. long attrnum;
  192.  
  193. status = CDFlib (SELECT_, CDF_, id,
  194.          GET_, ATTR_NUMBER_, attrName, &attrnum,
  195.          NULL_);
  196. if (status < CDF_WARN)            /* shouldn't be any INFO codes */
  197.   return status;
  198. else
  199.   return attrnum;
  200. }
  201.  
  202. /******************************************************************************
  203. * CDFattrRename.
  204. ******************************************************************************/
  205.  
  206. #if !C_INTERFACE_MACROS
  207. CDFstatus CDFattrRename(id,attrNum,attrName)
  208. CDFid    id;         /* in -- CDF id */
  209. long    attrNum;    /* in -- attribute to rename 0..nAttributes-1*/
  210. char    *attrName;    /* in -- new name for attribute */
  211. {
  212. return CDFlib (SELECT_, CDF_, id,
  213.             ATTR_, attrNum,
  214.            PUT_, ATTR_NAME_, attrName,
  215.            NULL_);
  216. }
  217. #endif
  218.  
  219. /******************************************************************************
  220. * CDFattrInquire.
  221. ******************************************************************************/
  222.  
  223. #if !C_INTERFACE_MACROS
  224. CDFstatus CDFattrInquire(id,attrNum,attrName,attrScope,maxEntry)
  225. CDFid    id;        /* in -- CDF id */
  226. long    attrNum;    /* in -- attribute number, 0..nAttributes-1 */
  227. char    *attrName;    /* out -- attribute name, NUL-terminated */
  228. long    *attrScope;    /* out -- scope of attribute, GLOBAL or
  229.                VARIABLE */
  230. long    *maxEntry;    /* out -- maximum entry number for attribute */
  231. {
  232. return CDFlib (SELECT_, CDF_, id,
  233.             ATTR_, attrNum,
  234.            GET_, ATTR_NAME_, attrName,
  235.              ATTR_SCOPE_, attrScope,
  236.              ATTR_MAXENTRY_, maxEntry,
  237.            NULL_);
  238. }
  239. #endif
  240.  
  241. /******************************************************************************
  242. * CDFattrEntryInquire.
  243. ******************************************************************************/
  244.  
  245. #if !C_INTERFACE_MACROS
  246. CDFstatus CDFattrEntryInquire(id,attrNum,entryNum,dataType,numElements)
  247. CDFid    id;        /* in -- CDF id */
  248. long    attrNum;    /* in -- attribute number, 0..nAttributes-1 */
  249. long    entryNum;    /* in -- entry number if GLOBAL scope attribute,
  250.                entryNum >= 0.
  251.                -- variable number if VARIABLE scope 
  252.                attribute, 0..nVariables-1 */
  253. long    *dataType;    /* out -- data type of this attribute entry */
  254. long    *numElements;    /* out -- number of elements of the data type */
  255. {
  256. return CDFlib (SELECT_, CDF_, id,
  257.             ATTR_, attrNum,
  258.             ENTRY_, entryNum,
  259.            GET_, ENTRY_DATATYPE_, dataType,
  260.              ENTRY_NUMELEMS_, numElements,
  261.            NULL_);
  262. }
  263. #endif
  264.  
  265. /******************************************************************************
  266. * CDFattrPut.
  267. ******************************************************************************/
  268.  
  269. #if !C_INTERFACE_MACROS
  270. CDFstatus CDFattrPut(id,attrNum,entryNum,dataType,numElements,value)
  271. CDFid    id;        /* in -- CDF id */
  272. long    attrNum;    /* in -- attribute number, 0..nAttributes-1 */
  273. long    entryNum;    /* in -- entry number if GLOBAL attribute,
  274.                entryNum >= 0.
  275.                -- variable number if VARIABLE attribute,
  276.                0..nVariables-1 */
  277. long    dataType;    /* in -- data type of this attribute entry */
  278. long    numElements;    /* in -- number of elements of the data type */
  279. void    *value;            /* in -- attribute entry value */
  280. {
  281. return CDFlib (SELECT_, CDF_, id,
  282.             ATTR_, attrNum,
  283.             ENTRY_, entryNum,
  284.            PUT_, ENTRY_DATA_, dataType, numElements, value,
  285.            NULL_);
  286. }
  287. #endif
  288.  
  289. /******************************************************************************
  290. * CDFattrGet.
  291. ******************************************************************************/
  292.  
  293. #if !C_INTERFACE_MACROS
  294. CDFstatus CDFattrGet(id,attrNum,entryNum,value)
  295. CDFid    id;        /* in -- CDF id */
  296. long    attrNum;    /* in -- attribute number, 0..nAttributes-1 */
  297. long    entryNum;    /* in -- entry number if GLOBAL attribute,
  298.                entryNum >= 0.
  299.                -- variable number if VARIABLE attribute,
  300.                0..nVariables-1 */
  301. void    *value;     /* out -- attribute entry value */
  302. {
  303. return CDFlib (SELECT_, CDF_, id,
  304.             ATTR_, attrNum,
  305.             ENTRY_, entryNum,
  306.            GET_, ENTRY_DATA_, value,
  307.            NULL_);
  308. }
  309. #endif
  310.  
  311. /******************************************************************************
  312. * CDFvarCreate.
  313. ******************************************************************************/
  314.  
  315. #if !C_INTERFACE_MACROS
  316. CDFstatus CDFvarCreate(id,varName,dataType,numElements,recVariance,dimVariances,
  317.                varNum)
  318. CDFid    id;        /* in -- CDF id */
  319. char    *varName;    /* in -- variable name */
  320. long    dataType;    /* in -- symbolic CDF datatype */
  321. long    numElements;    /* in -- number of elements of dataType; must be
  322.                  1 if not CDF_CHAR or CDF_UCHAR */
  323. long    recVariance;    /* in -- record variance { VARY, NOVARY} */
  324. long    dimVariances[]; /* in -- dimension vector [{VARY, NOVARY},,,] */
  325. long    *varNum;    /* out -- attribute number */
  326. {
  327. return CDFlib (SELECT_, CDF_, id,
  328.            CREATE_, VAR_, varName, dataType, numElements,
  329.                   recVariance, dimVariances, varNum,
  330.            NULL_);
  331. }
  332. #endif
  333.  
  334. /******************************************************************************
  335. * CDFvarNum.  Can't implement with macro since it is the variable number
  336. * which is to be returned (unless an error).
  337. ******************************************************************************/
  338.  
  339. long CDFvarNum(id,varName)
  340. CDFid    id;        /* in -- CDF id */
  341. char    *varName;    /* in -- variable name */
  342. {
  343. CDFstatus status;
  344. long varNum;
  345.  
  346. status = CDFlib (SELECT_, CDF_, id,
  347.          GET_, VAR_NUMBER_, varName, &varNum,
  348.          NULL_);
  349. if (status < CDF_WARN)
  350.   return status;
  351. else
  352.   return varNum;
  353. }
  354.  
  355. /******************************************************************************
  356. * CDFvarRename.
  357. ******************************************************************************/
  358.  
  359. #if !C_INTERFACE_MACROS
  360. CDFstatus CDFvarRename(id,varNum,varName)
  361. CDFid    id;         /* in -- CDF id */
  362. long    varNum;        /* in -- variable to rename 0..nVariables-1 */
  363. char    *varName;    /* in -- new name for variable */
  364. {
  365. return CDFlib (SELECT_, CDF_, id,
  366.             VAR_, varNum,
  367.            PUT_, VAR_NAME_, varName,
  368.            NULL_);
  369. }
  370. #endif
  371.  
  372. /******************************************************************************
  373. * CDFvarInquire.
  374. ******************************************************************************/
  375.  
  376. #if !C_INTERFACE_MACROS
  377. CDFstatus CDFvarInquire(id,varNum,varName,dataType,numElements,recVariance,
  378.             dimVariance)
  379. CDFid    id;        /* in -- CDF id */
  380. long    varNum;        /* in -- variable number, 0..nVariables-1 */
  381. char    *varName;    /* out-- name of variable, null-terminated */
  382. long    *dataType;    /* out-- symbolic CDF datatype */
  383. long    *numElements;    /* out-- number of elements of dataType; will be 1 if
  384.                  not CDF_CHAR or CDF_UCHAR */
  385. long    *recVariance;    /* out-- record variance {VARY,NOVARY} (T/F) */
  386. long    dimVariance[];  /* out-- dimension vector [{VARY, NOVARY},,,] */
  387. {
  388. return CDFlib (SELECT_, CDF_, id,
  389.             VAR_, varNum,
  390.            GET_, VAR_NAME_, varName,
  391.              VAR_DATATYPE_, dataType,
  392.              VAR_NUMELEMS_, numElements,
  393.              VAR_RECVARY_, recVariance,
  394.              VAR_DIMVARYS_, dimVariance,
  395.            NULL_);
  396. }
  397. #endif
  398.  
  399. /******************************************************************************
  400. * CDFvarGet.
  401. ******************************************************************************/
  402.  
  403. #if !C_INTERFACE_MACROS
  404. CDFstatus CDFvarGet(id,varNum,recNum,indices,value)
  405. CDFid    id;        /* in -- CDF id */
  406. long    varNum;        /* in -- variable number, 0..nVariables-1 */
  407. long    recNum;        /* in -- record number, >= 0 */
  408. long    indices[];    /* in -- indices of item, CDF dimensionality */
  409. void    *value;      /* out -- buffer containing variable datum */
  410. {
  411. return CDFlib (SELECT_, CDF_, id,
  412.             VAR_, varNum,
  413.             CDF_RECNUMBER_, recNum,
  414.             CDF_DIMINDICES_, indices,
  415.            GET_, VAR_DATA_, value,
  416.            NULL_);
  417. }
  418. #endif
  419.  
  420. /******************************************************************************
  421. * CDFvarPut.
  422. ******************************************************************************/
  423.  
  424. #if !C_INTERFACE_MACROS
  425. CDFstatus CDFvarPut(id,varNum,recNum,indices,value)
  426. CDFid    id;        /* in -- CDF id */
  427. long    varNum;        /* in -- variable number, 0..nVariables-1 */
  428. long    recNum;        /* in -- record number, >= 0 */
  429. long    indices[];    /* in -- indices of item, CDF dimensionality */
  430. void    *value;      /* in -- buffer containing variable datum */
  431. {
  432. return CDFlib (SELECT_, CDF_, id,
  433.             VAR_, varNum,
  434.             CDF_RECNUMBER_, recNum,
  435.             CDF_DIMINDICES_, indices,
  436.            PUT_, VAR_DATA_, value,
  437.            NULL_);
  438. }
  439. #endif
  440.  
  441. /******************************************************************************
  442. * CDFvarHyperGet.
  443. ******************************************************************************/
  444.  
  445. #if !C_INTERFACE_MACROS
  446. CDFstatus CDFvarHyperGet(id,varNum,recStart,recCount,recInterval,
  447.              indices,counts,intervals,buffer)
  448. CDFid    id;        /* in -- CDF id */
  449. long    varNum;        /* in -- variable number, 0..nVariables-1 */
  450. long    recStart;    /* in -- starting record, 0..nRecords-1*/
  451. long    recCount;    /* in -- number of records  */
  452. long    recInterval;    /* in -- record subsample interval    */
  453. long    indices[];    /* in -- starting indices, CDF dimensionality */
  454. long    counts[];    /* in -- items to get in each dimension */
  455. long    intervals[];    /* in -- dimension subsampling intervals */
  456. void    *buffer;    /* out-- buffer to write to  */
  457. {
  458. return CDFlib (SELECT_, CDF_, id,
  459.             VAR_, varNum,
  460.             CDF_RECNUMBER_, recStart,
  461.             CDF_RECCOUNT_, recCount,
  462.             CDF_RECINTERVAL_, recInterval,
  463.             CDF_DIMINDICES_, indices,
  464.             CDF_DIMCOUNTS_, counts,
  465.             CDF_DIMINTERVALS_, intervals,
  466.            GET_, VAR_HYPERDATA_, buffer,
  467.            NULL_);
  468. }
  469. #endif
  470.  
  471. /******************************************************************************
  472. * CDFvarHyperPut.
  473. ******************************************************************************/
  474.  
  475. #if !C_INTERFACE_MACROS
  476. CDFstatus CDFvarHyperPut(id,varNum,recStart,recCount,recInterval,
  477.              indices,counts,intervals,buffer)
  478. CDFid    id;        /* in -- CDF id */
  479. long    varNum;        /* in -- variable number, 0..nVariables-1 */
  480. long    recStart;    /* in -- starting record, 0..nRecords-1*/
  481. long    recCount;    /* in -- number of records  */
  482. long    recInterval;    /* in -- record subsample interval    */
  483. long    indices[];    /* in -- starting indices, CDF dimensionality */
  484. long    counts[];    /* in -- items to get in each dimension */
  485. long    intervals[];    /* in -- dimension subsampling intervals */
  486. void    *buffer;    /* out-- buffer to read from */
  487. {
  488. return CDFlib (SELECT_, CDF_, id,
  489.             VAR_, varNum,
  490.             CDF_RECNUMBER_, recStart,
  491.             CDF_RECCOUNT_, recCount,
  492.             CDF_RECINTERVAL_, recInterval,
  493.             CDF_DIMINDICES_, indices,
  494.             CDF_DIMCOUNTS_, counts,
  495.             CDF_DIMINTERVALS_, intervals,
  496.            PUT_, VAR_HYPERDATA_, buffer,
  497.            NULL_);
  498. }
  499. #endif
  500.  
  501. /******************************************************************************
  502. * CDFvarClose.
  503. ******************************************************************************/
  504.  
  505. #if !C_INTERFACE_MACROS
  506. CDFstatus CDFvarClose(id,varNum)
  507. CDFid    id;        /* in -- CDF id */
  508. long     varNum;     /* in -- variable number, 0..nVariables-1 */
  509. {
  510. return CDFlib (SELECT_, CDF_, id,
  511.             VAR_, varNum,
  512.            CLOSE_, VAR_,
  513.            NULL_);
  514. }
  515. #endif
  516.